
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class CalendarSeeker {
       public final static short DAYS_UP_LIMIT = 31;
       public final static short DAYS_DOWN_LIMIT = 1;
       public final static short MONTHS_UP_LIMIT = 12;
       public final static short MONTHS_DOWN_LIMIT = 1;
       public final static short YEARS_UP_LIMIT = 3000;
       public final static short YEARS_DOWN_LIMIT = 1;
    
	public char GetDay(char day, char month, short year) {
		int a = (14 - month) / 12;
		int y = year - a;
		int m = month + 12 * a - 2;
		return (char) ((7000 + (day + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12)) % 7);
	}

	public short CheckCalendarData(String msg, short downLimit, short upLimit) {
		short n;
		while(true) {
			try {
                            System.out.println("Input " + msg + " please");
                            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                            String str = in.readLine();
                            n = (short) new Integer(str).intValue();
                            if((n < downLimit) || (n > upLimit)) {
				throw new Exception();
                            }
                                
                            return n;
				
			}catch(Exception ex) {
				System.out.println("Input " + msg + " correctly please!!!");
			}
		}
	}
	
	public static void main(String[] args) {
		CalendarSeeker myCalendarSeeker = new CalendarSeeker();
		char day = (char) myCalendarSeeker.CheckCalendarData("day", DAYS_DOWN_LIMIT, DAYS_UP_LIMIT);
		char month = (char) myCalendarSeeker.CheckCalendarData("month", MONTHS_DOWN_LIMIT, MONTHS_UP_LIMIT);
		short year = myCalendarSeeker.CheckCalendarData("year", YEARS_DOWN_LIMIT, YEARS_UP_LIMIT);
		
		System.out.println("Your day is");
		switch (myCalendarSeeker.GetDay(day, month, year)) {
			case 0:
					System.out.println("SUNDAY");
					break;
			case 1:
					System.out.println("MONDAY");
					break;
			case 2:
					System.out.println("Tuesday");
					break;
			case 3:
					System.out.println("WEDNESDAY");
					break;
			case 4:
					System.out.println("Thursday");
					break;
			case 5:
					System.out.println("FRIDAY");
					break;
			case 6:
					System.out.println("SATURDAY");
					break;
		}	
	}
}